<!--
 * @Description: 
 * @Author: kangjie
 * @Date: 2021-09-17 14:07:05
 * @LastEditors: guyuelong
 * @LastEditTime: 2021-09-22 08:25:58
-->
<template>
  <div>
    <!-- 头部 -->
    <!-- {{category}} -->
    <div class="header">
      <div class="header_top">
        <!-- 容器居中显示 -->
        <div class="wrapper">
          <div class="left">山西农大新闻网欢迎您</div>
          <div class="right">学校主页</div>
        </div>
      </div>
      <div class="header_mian">
        <div class="wrapper">
          <div class="logo" @click="toHome">
            <img src="/resource/img/logo.png" alt />
          </div>
          <ul>
            <li
              :class="$route.query.name === item.name ? 'current' : ''"
              v-for="item in category"
              @click="toJump(item)"
              :key="item.id"
            >
              {{ item.name }}
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- /头部 -->
  </div>
</template>
<script>
import { get } from "../utils/request";
export default {
  data() {
    return {
      category: [],
    };
  },
  created() {
    this.loadCategory();
  },
  // 方法 事件处理程序
  methods: {
    toHome() {
      //  跳转到主页
      this.$router.push({
        path: "/home",
      });
    },
    // 跳转
    toJump(item) {
      // 跳转到list页面 编程式路由导航
      // alert(JSON.stringify(item))

      this.$router.push({
        // 放跳转的路径 和携带的参数
        path: "/list",
        query: item,
      });
    },
    // 所有路径都要写在方法中
    // 加载所有栏目
    loadCategory() {
      let url = "/index/category/findAll";
      get(url).then((res) => {
        this.category = res.data;
        // this.name=res.data.name;
      });
    },
  },
};
</script>



<style lang="scss">
// 头部样式
.header {
  .header_top {
    background-color: #028b39;
    color: white;

    & > .wrapper::after {
      display: block;
      content: "";
      clear: both;
    }
    .left,
    .right {
      line-height: 3em;
    }
    .left {
      float: left;
    }
    .right {
      float: right;
    }
  }
  .header_mian {
    & > .wrapper {
      display: flex;
      justify-content: space-between;
      position: relative;
      ul {
        position: absolute;
        bottom: 0;
        right: 0;
        li {
          float: left;
          padding: 0.8em;
        }
        li:hover {
          background-color: #028b39;
          color: white;
          cursor: pointer;
        }
        li.current {
          background-color: #028b39;
          color: white;
          cursor: pointer;
        }
      }
    }
    .logo {
      padding: 1em;
      cursor: pointer;
      img {
        height: 50px;
      }
    }
  }
}
</style>